<?php
require('config.php');

        $phone=$_REQUEST['phone'];
        $content=$_REQUEST['content'];
        $type=$_REQUEST['type'];
        $time=date('Y-m-d H:i:s');
        if($type==0)
        {
        	if(isset($_REQUEST['user_id']))
	        {
				$user_id=$_REQUEST['user_id'];
				$sql="INSERT INTO ".$oto."_suggest (`userId`,`phone`,`content`,`createTime`) VALUES ('$user_id','$phone','$content','$time')";
	        	$result=$db->query($sql);
	        	if($result)
	        	{
	        		$data[0]['pan']="1";
	        	}
	        	else
	        	{
	        		$data[0]['pan']="-1";
	        	}
	        }
	        else
	        {
				$sql="INSERT INTO ".$oto."_suggest (`phone`,`content`,`createTime`) VALUES ('$phone','$content','$time')";
	        	$result=$db->query($sql);
	        	if($result)
	        	{
	        		$data[0]['pan']="1";
	        	}
	        	else
	        	{
	        		$data[0]['pan']="-1";
	        	}
	        }
        }
        else if($type==1)
        {
        	$object=$_REQUEST['object'];
        	$user_id=$_REQUEST['user_id'];
        	$wb_id=0;
        	if(isset($_REQUEST['wb_id'])) $wb_id=$_REQUEST['wb_id'];
        	$sql="select * from `".$oto."_suggest` where userId='{$user_id}' and `object`='{$wb_id}'";
			$result=$db->query($sql);
			while($row=$result->fetch_assoc()){
				$suggest[]=$row;//将取得的所有数据赋值给person_info数组
			}
			if(isset($suggest))
			{
				$data[0]['pan']="-1";
				$data[0]['msg']="您已经投诉过了";
			}
			else
			{
				$sql="INSERT INTO ".$oto."_suggest (`userId`,`phone`,`content`,`object`,`complaintType`,`createTime`) VALUES ('$user_id','$phone','$content','$wb_id','1','$time')";
				//file_put_contents("tsxx.txt", "\r\n".$sql."\r\n", FILE_APPEND);
	        	$result=$db->query($sql);
	        	if($result)
	        	{
	        		$data[0]['pan']="1";
	        		$data[0]['msg']="投诉成功";
	        	}
	        	else
	        	{
	        		$data[0]['pan']="-1";
	        		$data[0]['msg']="投诉失败";
	        	}
			}
        }
        else if($type==2)
        {
        	$shopId=$_REQUEST['shopId'];
        	$time2=time();
        	if(isset($_REQUEST['user_id']))
	        {
				$user_id=$_REQUEST['user_id'];
				$sql="INSERT INTO ".$oto."_report (`userId`,`phone`,`content`,`time`,`shopId`) VALUES ('$user_id','$phone','$content','$time2','$shopId')";
	        	$result=$db->query($sql);
	        	if($result)
	        	{
	        		$data[0]['pan']="1";
	        	}
	        	else
	        	{
	        		$data[0]['pan']="-1";
	        	}
	        }
	        else
	        {
				$sql="INSERT INTO ".$oto."_report (`phone`,`content`,`time`,`shopId`) VALUES ('$phone','$content','$time2','$shopId')";
	        	$result=$db->query($sql);
	        	if($result)
	        	{
	        		$data[0]['pan']="1";
	        	}
	        	else
	        	{
	        		$data[0]['pan']="-1";
	        	}
	        }
        }
        echo json_encode($data);
?>